<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Filters.aspx.vb" Inherits="Filters" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div>
      <asp:SqlDataSource ID="FilterDates" runat="server" ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>"
        DeleteCommand="DELETE FROM [FilterDates] WHERE [FilterDateId] = @FilterDateId"
        InsertCommand="INSERT INTO FilterDates(DataSourceVendorId, StartDate, EndDate, FilterTypeId, AgentCount) VALUES (@DataSourceVendorId, @StartDate, @EndDate, @FilterTypeId, @AgentCount)"
        SelectCommand="SELECT FilterDates.FilterDateId, FilterDates.DataSourceVendorId, FilterDates.StartDate, FilterDates.EndDate, FilterTypes.FilterTypeShort, FilterDates.AddDate, FilterDates.AddByUser, Vendors.Name + ' ' + DataSources.DataSource AS Source, FilterDates.FilterTypeId, FilterDates.AgentCount FROM FilterDates INNER JOIN DataSourceVendor ON FilterDates.DataSourceVendorId = DataSourceVendor.DataSourceVendorId INNER JOIN DataSources ON DataSourceVendor.DataSourceId = DataSources.DataSourceId INNER JOIN Vendors ON DataSourceVendor.VendorId = Vendors.VendorId INNER JOIN FilterTypes ON FilterDates.FilterTypeId = FilterTypes.FilterTypeId WHERE (Vendors.VendorId = @VendorId) ORDER BY Source"
        UpdateCommand="UPDATE FilterDates SET DataSourceVendorId = @DataSourceVendorId, StartDate = @StartDate, EndDate = @EndDate, FilterTypeId = @FilterTypeId, AddDate = @AddDate, AddByUser = @AddByUser, AgentCount = @AgentCount WHERE (FilterDateId = @FilterDateId)">
        <DeleteParameters>
          <asp:Parameter Name="FilterDateId" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
          <asp:Parameter Name="DataSourceVendorId" Type="Int32" />
          <asp:Parameter Name="StartDate" Type="DateTime" />
          <asp:Parameter Name="EndDate" Type="DateTime" />
          <asp:Parameter Name="FilterTypeId" Type="Byte"/>
          <asp:Parameter Name="AddDate" Type="DateTime" />
          <asp:Parameter Name="AddByUser" Type="String" />
          <asp:Parameter Name="AgentCount" />
          <asp:Parameter Name="FilterDateId" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
          <asp:Parameter Name="DataSourceVendorId" Type="Int32" />
          <asp:Parameter Name="StartDate" Type="DateTime" />
          <asp:Parameter Name="EndDate" Type="DateTime" />
          <asp:Parameter Name="FilterTypeId" Type="Byte"/>
          <asp:Parameter Name="AgentCount" />
        </InsertParameters>
        <SelectParameters>
          <asp:ControlParameter ControlID="ddlVendor" Name="VendorId" PropertyName="SelectedValue" />
        </SelectParameters>
      </asp:SqlDataSource>
      <asp:SqlDataSource ID="DataSourceVendor" runat="server" ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>"
        SelectCommand="SELECT DataSourceVendorId, Name + ' ' + DataSource AS Source FROM View_DataSourceVendor ORDER BY Source">
      </asp:SqlDataSource>
      <asp:SqlDataSource ID="FilterTypes" runat="server" ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>" SelectCommand="SELECT [FilterTypeId], [FilterType] FROM [FilterTypes]"></asp:SqlDataSource>
      <asp:SqlDataSource ID="sqlVendors" runat="server" ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>"
        SelectCommand="SELECT [VendorId], [Name] FROM [Vendors] ORDER BY [Name]"></asp:SqlDataSource>
      &nbsp;
      &nbsp;&nbsp;
      <br />
      <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/FilterEdit.aspx">Add new filter</asp:HyperLink>&nbsp;<br />
      <br />
      <asp:DropDownList ID="ddlVendor" runat="server" AutoPostBack="True" DataSourceID="sqlVendors"
        DataTextField="Name" DataValueField="VendorId" Width="222px">
      </asp:DropDownList><br />
      <br />
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="FilterDateId"
    DataSourceID="FilterDates">
    <Columns>
      <asp:TemplateField>
        <ItemTemplate>
        <asp:HyperLink ID="LinkButton2" runat="server" Text="Edit" NavigateUrl='<%# FormatEditURL (eval("FilterDateId")) %>' >Edit</asp:HyperLink>
<%--<asp:LinkButton runat="server" CommandName="Edit" >Edit</asp:LinkButton>
--%>          <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return confirm('Are you sure you want to delete this record?');"
            CommandName="Delete">Delete</asp:LinkButton>
        </ItemTemplate>
        <EditItemTemplate>
          <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Update">Update</asp:LinkButton>
          <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
        </EditItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="FilterDateId" HeaderText="FilterDateId" InsertVisible="False"
        ReadOnly="True" SortExpression="FilterDateId" Visible="False" />
      <asp:BoundField DataField="DataSourceVendorId" HeaderText="DataSourceVendorId" SortExpression="DataSourceVendorId"
        Visible="False" />
      <asp:TemplateField HeaderText="Source" SortExpression="Source">
        <EditItemTemplate>
          <asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="DataSourceVendor"
            DataTextField="Source" DataValueField="DataSourceVendorId" SelectedValue='<%# Bind("DataSourceVendorId", "{0}") %>'
            Width="227px">
          </asp:DropDownList>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="Label1" runat="server" Text='<%# Bind("Source") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="StartDate" DataFormatString="{0:d}" HeaderText="StartDate"
        HtmlEncode="False" SortExpression="StartDate" />
      <asp:BoundField DataField="EndDate" DataFormatString="{0:d}" HeaderText="EndDate"
        HtmlEncode="False" SortExpression="EndDate" />
      <asp:TemplateField HeaderText="Type" SortExpression="FilterTypeShort">
        <EditItemTemplate>
          <asp:DropDownList ID="DropDownList6" runat="server" DataSourceID="FilterTypes" DataTextField="FilterType"
            DataValueField="FilterTypeId" SelectedValue='<%# Bind("FilterTypeId") %>' Width="144px">
          </asp:DropDownList>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:Label ID="Label2" runat="server" Text='<%# Bind("FilterTypeShort") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="AgentCount" HeaderText="Agent Count" SortExpression="AgentCount" />
       <asp:BoundField DataField="AddDate" DataFormatString="{0:d}" HeaderText="AddDate"
        HtmlEncode="False" SortExpression="AddDate" />
      <asp:BoundField DataField="AddByUser" HeaderText="AddByUser" SortExpression="AddByUser" />
      <asp:BoundField DataField="FilterTypeId" HeaderText="FilterTypeId" SortExpression="FilterTypeId"
        Visible="False" />
    </Columns>
  </asp:GridView>
</asp:Content>